﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace Presentation
{
    public partial class QuanLyPhieuThue : Form
    {
        public QuanLyPhieuThue()
        {
            InitializeComponent();
        }

        public void layDSPhieuThue()
        {
            GridPhieuThue.Rows.Clear();
            List<PhieuThuePhongDTO> dsPhieuThue = PhieuThuePhongBUS.layDSPhieuThue();
            //MessageBox.Show(dsPhieuThue.Count.ToString(), "thongbao");

            for (int i = 0; i < dsPhieuThue.Count; i++)
            {
                GridPhieuThue.Rows.Add(dsPhieuThue[i].MaPhieuThue, dsPhieuThue[i].Phong.TenPhong, dsPhieuThue[i].NgayBatDauThue.ToString("dd/MM/yyyy"),dsPhieuThue[i].DaThanhToan);
                GridPhieuThue.Rows[GridPhieuThue.RowCount - 1].Tag = dsPhieuThue[i];

            }
        }

        private void LapPhieuThue_Load(object sender, EventArgs e)
        {
            layDSPhieuThue();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LapPhieuThue form0 = new LapPhieuThue();
            form0.ShowDialog();
            //layDSPhong();
            layDSPhieuThue();
        }



        private void GridPhieuThue_SelectionChanged_2(object sender, EventArgs e)
        {
            if (GridPhieuThue.CurrentRow.Tag != null)
            {
                PhieuThuePhongDTO phieuDuocChon = (PhieuThuePhongDTO)GridPhieuThue.CurrentRow.Tag;
            }
        }

        private void btn_CapNhat_Click(object sender, EventArgs e)
        {

            if (GridPhieuThue.CurrentRow.Tag != null)
            {
               PhieuThuePhongDTO phieuDuocChon = (PhieuThuePhongDTO)GridPhieuThue.CurrentRow.Tag;
               CapNhatPhieuThue form1 = new CapNhatPhieuThue();

               form1.truyenPhieu(phieuDuocChon);
               form1.ShowDialog();
            }
        }

        private void tbn_XoaPhieu_Click(object sender, EventArgs e)
        {
            if (GridPhieuThue.CurrentRow.Tag != null)
            {
                if (MessageBox.Show("Bạn có thật muốn xóa?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    PhieuThuePhongDTO phieuDuocChon = (PhieuThuePhongDTO)GridPhieuThue.CurrentRow.Tag;
                    bool ketQua = PhieuThuePhongBUS.xoa(phieuDuocChon.MaPhieuThue);
                    if (ketQua == false)
                    {
                        MessageBox.Show("Xóa thất bại");
                    }
                    else
                    {
                        MessageBox.Show("Xóa thành công");
                        layDSPhieuThue();
                    }
                }
            }
        }

        private void tb_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
